<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>上传头像</title>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title">
		<legend>图片列表</legend>
		<button type="button" class="layui-btn" id="test1">
			<i class="layui-icon" >&#xe67c</i>上传图片
		</button>
		<div class="layui-upload-list">
			<table class="layui-table">
				<thead>
					<tr>
						<th width="5%">文件名</th>
						<th width="10%">图片</th>
						<th width="10%">操作</th>
					</tr>
				</thead>
					<tbody id="demolist2"></tbody>
			</table>
		</div>
	</fieldset>
		
	<script type="text/javascript">
		var code = '<%=request.getParameter("code")%>';
		
		//按钮--submit监听--点击--执行function
		//按钮--upload渲染--点击--执行function
		renderUpload("test1","/employeeUploadServlet",{code:code},function(res){
// 			console.log(res)
			if(res.code==1){
				layer.msg("上传成功")
				showPic(res.image)
			}
		})
		
		init();
		
		function init(){
			ajax("/employee",{action:"get",code:code},"json",function(data){
				var image = data.image;
				if(image)
					showPic(image)
				else
					$("#demolist2").html('');
			})
			
		}
		function showPic(image){
			var html = "<tr><td>"+image+"</td>"
			+"<td><img src='/images/"+image+"' class = 'layui-upload-img'></td>"
			+"<td><input type='button' onclick='delPic()' class='layui-btn' value='删除'></td></tr>";
			$("#demolist2").html(html);
		}
		function delPic(){
			openConfirm(function(){
				ajax("/employee",{action:'delPic',code:code},"text",function(data){
					if(1==data){
						layer.msg("删除成功")
						$("#demolist2").html("");
					}
				})
			})
		}
		
		
</script>
</body>
</html>